﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Data;
using System.Configuration;
using System.IO;
using System.Net.Configuration;
using System.Net.Mail;


/// <summary>
/// Summary description for Email
/// </summary>
public class Email
{
    public static String FormAddress
    {
        get
        {
            SmtpSection cfg = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp");
            return cfg.Network.UserName;
        }
    }

    public string SendMail(string subject, string body, string to, bool isHtml, bool isSSL)
    {
        try
        {
            MailMessage mail = new MailMessage();

            mail.From = new MailAddress("DoAnC4W@gmail.com", "toantamvn.com");
            mail.To.Add(to);

            mail.Subject = "test";
            mail.Body = "test";
            mail.IsBodyHtml = isHtml;
            SmtpClient client = new SmtpClient();
            client.Credentials = new System.Net.NetworkCredential("DoAnC4W@gmail.com", "nhatkhanh");
            client.Port = 587;
            client.Host = "smtp.gmail.com";
            client.EnableSsl = true;
            client.Send(mail);

        }
        catch (SmtpException ex)
        {
            return ex.Message;
        }
        return "Send email successful!";
    }

    public string SendMail(string subject, string body, string from, string to, bool isHtml, bool isSSL, bool isCC)
    {
        try
        {
            MailMessage mail = new MailMessage();

            mail.From = new MailAddress(from, "toantamvn.com");
            mail.To.Add(to);
            if (isCC)
            {
                mail.CC.Add(from);
            }
            mail.Subject = subject;
            mail.Body = body;
            mail.IsBodyHtml = isHtml;
            SmtpClient client = new SmtpClient();
            client.Credentials = new System.Net.NetworkCredential("DoAnC4W@gmail.com", "nhatkhanh");//("info@toantamvn.com", "toiyeuvietnam");
            client.Port = 587;//25;
            client.Host = "smtp.gmail.com";//"mail.toantamvn.com";
            client.EnableSsl = isSSL;
            client.Send(mail);

        }
        catch (SmtpException ex)
        {
            return ex.Message;
        }
        return "Gửi mail thành công!";
    }

    public Email()
    {
        //
        // TODO: Add constructor logic here
        //
    }
}